package com.example.demo.generator.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.generator.domain.User;
import com.example.demo.generator.mapper.UserMapper;
import com.example.demo.generator.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author WSY
* @description 针对表【user(用户信息)】的数据库操作Service实现
* @createDate 2023-04-18 19:18:08
*/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
    implements UserService {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    @Transactional
    public void performTransaction() {
        try {
            // 更新商品库存
            jdbcTemplate.update("UPDATE user SET phone =11111 WHERE phone = ?", 298);

            // 创建订单
            jdbcTemplate.update("UPDATE user SET iii =2222 WHERE phone = ?", 2);

            System.out.println("事务已提交");
        } catch (Exception e) {
            System.out.println("事务已回滚：" + e.getMessage());
            throw e;
        }
    }


}




